/**
 * Copyright &copy; 2016 CNJSON All rights reserved.
 */
package com.hongsuan.pplive.modules.cms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cnjson.db.persistence.Page;
import com.cnjson.db.service.CrudService;
import com.cnjson.common.utils.StringUtils;
import com.hongsuan.pplive.modules.cms.dao.CategoryDao;
import com.hongsuan.pplive.modules.cms.dao.VideoDao;
import com.hongsuan.pplive.modules.cms.entity.Category;
import com.hongsuan.pplive.modules.cms.entity.Video;

/**
 * 视频管理Service
 * @author Susan
 * @version 2015-11-26
 */
@Service
@Transactional(readOnly = true)
public class VideoService extends CrudService<VideoDao, Video> {
    @Autowired
    private CategoryDao categoryDao;

	public Video get(String id) {
		return super.get(id);
	}

	public List<Video> findList(Video video) {
		return super.findList(video);
	}

	public Page<Video> findPage(Page<Video> page, Video video) {
        if (video.getCategory()!=null && StringUtils.isNotBlank(video.getCategory().getId()) && !Category.isRoot(video.getCategory().getId())){
            Category category = categoryDao.get(video.getCategory().getId());
            if (category==null){
                category = new Category();
            }
            category.setParentIds(category.getId());
            video.setCategory(category);
        }
        else{
            video.setCategory(new Category());
        }
		return super.findPage(page, video);
	}

	@Transactional(readOnly = false)
	public void save(Video video) {
		super.save(video);
	}

	@Transactional(readOnly = false)
	public void delete(Video video) {
		super.delete(video);
	}

}